package com.lanou.zy.projecta.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.zy.projecta.R;

/**
 * Created by dllo on 15/11/5.
 */
public class WebViewActivity extends AppCompatActivity implements View.OnClickListener {
    private WebView webView;
    private TextView webNameTv;
    private ImageView fnsAll_backToRecommend_Iv;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_webview);
        init();
    }

    private void init() {
        webNameTv = (TextView) findViewById(R.id.webNameTv);
        webView = (WebView) findViewById(R.id.webView);
        fnsAll_backToRecommend_Iv = (ImageView) findViewById(R.id.fnsAll_backToRecommend_Iv);
        fnsAll_backToRecommend_Iv.setOnClickListener(this);
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);
        // 监听浏览器引擎
        webView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);
                Log.i("lanou3g", "加载网页加载进度:" + newProgress);
            }
        });
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onReceivedError(WebView view, int errorCode,
                                        String description, String failingUrl) {
                super.onReceivedError(view, errorCode, description, failingUrl);
                Log.i("lanou3g", errorCode + "  " + description);
            }
        });

        Intent intent = getIntent();
        String url = intent.getStringExtra("url");
        webNameTv.setText(intent.getStringExtra("name"));
        Log.d("WebViewActivity", "--------" + url);
        webView.loadUrl(url);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.fnsAll_backToRecommend_Iv:
                onBackPressed();
                finish();
                break;
        }
    }
}
